<?php
$this->pageTitle=Yii::app()->name . ' - Поиск клиента';
$this->breadcrumbs=array(
	'Поиск клиента',
);
?>

<?php $this->renderPartial('//menus/_operator_menu',array('active'=>'clients'))?>
<fieldset>
	<legend>Поиск клиента</legend>

	<?php if(count(Yii::app()->searchHistory->getClientsHistory())):?>
	<div class="well">
		<p style="text-decoration: underline;">Истроия поиска:</p>
		<div>
			<?php foreach(Yii::app()->searchHistory->getClientsHistory() as $item):?>
			<?=CHtml::link('<span class="label">'.$item['fio'].'</span>',Yii::app()->createUrl('clients/view',array('id'=>$item['id'])));?>
			<?php endforeach;?>
		</div>
	</div>
	<?php endif;?>

	<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
		'id'=>'search-client-form',
		'type'=>'vertical',
		'method'=>'get',
		'htmlOptions'=>array('style'=>'margin: 0;','class'=>'well')
	)); ?>

	<?php if($SearchClientForm->getError('no_data')):?>
	<div class="alert alert-error">
		<strong></strong> <?=$SearchClientForm->getError('no_data')?>
	</div>
	<?php endif;?>

	<div class="row">
		<div class="span4">
			<?php echo $form->textFieldRow($SearchClientForm,'surname',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span4">
			<?php echo $form->textFieldRow($SearchClientForm,'name',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span3">
			<?php echo $form->textFieldRow($SearchClientForm,'patronymic',array('class'=>'input-block-level')); ?>
		</div>
	</div>

	<div class="row">
		<div class="span1">
			<?php echo $form->textFieldRow($SearchClientForm,'series',array('class'=>'input-block-level')); ?>
		</div>
		<div class="span2">
			<?php echo $form->textFieldRow($SearchClientForm,'number',array('class'=>'input-block-level')); ?>
		</div>
	</div>

	<div style="margin-top: 10px;">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'success',
			'loadingText'=>'Идет поиск...',
			'label'=>'Найти',
			'htmlOptions'=>array('id'=>'search-button','style'=>'width:140px;')
		)); ?>
	</div>

	<?php $this->endWidget(); ?>

	<?php if($dataProvider !== null):?>
	<div>
		<?php $this->widget('bootstrap.widgets.TbGridView', array(
			'type'=>'striped condensed',
			'dataProvider'=>$dataProvider,
			'ajaxUpdate'=>false,
			'enablePagination'=>true,
			'template'=>"{items}{pager}",
			'emptyText'=>'Клиент с такими данными не найден. '.CHtml::link("Добавить его в базу?",Yii::app()->createUrl('clients/add',array('surname'=>$SearchClientForm->surname,'name'=>$SearchClientForm->name,'patronymic'=>$SearchClientForm->patronymic))),
			'showTableOnEmpty'=>false,
			'columns'=>array(
				array(
					'name'=>'surname',
					'header'=>'ФИО',
					'value'=>'CHtml::link($data->surname." ".$data->name." ".$data->patronymic,Yii::app()->createUrl("clients/view",array("id"=>$data->id)))',
					'type'=>'raw'
				),
				array(
					'name'=>'dob',
					'value'=>'date("d.m.Y",strtotime($data->dob))'
				)
			),
		)); ?>
	</div>

	<?php if($dataProvider->totalItemCount):?>
	<div style="margin-top: 10px;">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'link',
			'url'=>Yii::app()->createUrl('clients/add'),
			'type'=>'primary',
			'label'=>'Добавить нового клиента',
		)); ?>
	</div>
	<?php endif;?>
	<?php endif;?>
</fieldset>

<script type="text/javascript">
	$(document).ready(function(){
		$('#search-button').click(function() {
			$(this).button('loading'); // call the loading function
		});

		$('#SearchForm_surname').focus();
	});
</script>